package com.example.mybrowser.Pack;

import java.io.Serializable;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


public class PackageEntry implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1132119794494837659L;
	public String URL;
	public String MD5;
	public String Response;
	public byte[] Content;
	public int UseCache;
	
	public void GenerateMD5(){
		MessageDigest messageDigest = null;
		try
		{
			messageDigest = MessageDigest.getInstance("MD5");
			messageDigest.update(Content, 0, Content.length);
		
		}
		catch (NoSuchAlgorithmException e)
		{
			e.printStackTrace();
		}
		MD5 =  toHexString(messageDigest.digest());
	}
	
	private String toHexString(byte[] b) 
	{
		char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
		StringBuilder sb = new StringBuilder(b.length * 2);  
		for (int i = 0; i < b.length; i++) 
	    {
	    	sb.append(HEX_DIGITS[(b[i] & 0xf0) >>> 4]);  
	    	sb.append(HEX_DIGITS[b[i] & 0x0f]);  
	    }
	    return sb.toString();  
	}
}

